<?php include_partial('common/flashes') ?>
<form id="question-form" action="<?php echo url_for('@question_new') ?>" method="post">
    <div id="question-block">
        <?php echo $form->renderHiddenFields(false) ?>
        <div id="top-question-block">
            <?php include_partial("common/input_field", array("form" => $form, "field" => "enquiry", "show_label" => false)) ?>              
            <div id="bottom-question-block">
                <span class="question-counter-numerator" id="question-counter" disabled="disabled">0</span><span class="question-counter-denominator">/150</span><button id="submit-question" class="blue-button-30" type="submit">Ask now</button>             
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){        
        $('#question_enquiry').focus(function() { 
            $this = $(this);
            $this.height(54);
            if($.trim($this.val()) == $this.attr('title')) {
                $this.val('');
            }            
        }).blur(function() {
            $this = $(this);
            if(!$.trim($this.val())) {
                $this.val($this.attr('title'));
                $this.height(27);
            }
        });
        
        $('#question_enquiry').keydown(function(event) {
            $this = $(this);
            $questionCounter = $('#question-counter');
            if($this.val().length > 150 && event.which != 8 && event.which != 46){
                return false;
            }
            else{
                newQuestionCounter = $this.val().length;
                $questionCounter.html(newQuestionCounter);
                
                healthQualityPercent = $('#health-quality-percent').html();                
                healthQualityPercent = parseFloat(parseFloat(healthQualityPercent) + 0.033333333);
                
                // update the health quality value
                $('#health-quality-percent').html(healthQualityPercent);
            }
        });
        
        // make an attempt to submit this form
        $('#submit-question').click(function() {            
            $("#question-form").hide();
            $("#question-form-holder").append(loadingHtml);
            
            if($.trim($('#question_enquiry').val()) == 'Ask a new question...')
            {
                $('#question_enquiry').val('');
            }
            $('#question-form').ajaxSubmit(function(data){
                if($.trim(data) == 'signin'){
                    $('#question_enquiry').val('Ask a new question...');         
                    $("#question-form-holder").load("/question/new")
                    openPopup('/question/anonymous', "730px", "635px");
                }
                else{
                    $("#question-form-holder").html(data);                
                }
            });
            return false;
        });
    });
    //]]>
</script>